#include "loading.h"
#include "ui_loading.h"

Loading::Loading(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Loading)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::Window);
    //填充背景
    this->setAutoFillBackground(true);
    this->setPalette(QPalette(QColor( 0, 0, 0, 255)));
    //动画
    movie = new QMovie(this);
    //设置播放文件
    movie->setFileName(":/resources/fire.gif");
    //设置缓存模式
    movie->setCacheMode(QMovie::CacheAll);
    //显示到label上
    ui->label->setMovie(movie);
    //开始播放
    movie->start();

    player = new QMediaPlayer;
#ifdef WIN32
    player->setMedia(QUrl::fromLocalFile("D:/qt/test/ignition.mp3"));
#endif

#ifdef ANDROID
    player->setMedia(QUrl::fromLocalFile("/sdcard/music/ignition.mp3"));
#endif
    player->play();

    connect( this, SIGNAL(over()), this, SLOT(loadingEnd()));
}

Loading::~Loading()
{
    delete ui;
}

/**
 * @brief 开机动画结束
 *
 */
void Loading::loadingEnd()
{
    movie->stop();
    player->stop();
    this->hide();
    this->deleteLater();
}
